Repository navigation
Disallow cookies explicitly - #1447
Conversation
|
I'm not convinced. Can you explain what you were doing such that this was an issue? Or otherwise some theoretical mode of interaction in which this is problematic? Note that subclassing SDK base classes to communicate with customer run services is a supported use case. So even if we were aligned that this should change, I think we need to discuss whether or not it waits for a major release. |
|
The core issue is the misalignment of session state leaking into the request only if a redirect occurs. The current code uses If a redirect occurs, I'm open to a different fix, but I'd like to ensure that hosts cannot set session state (specifically, cookies) that leaks out on redirects. |
|
I should clarify what I wrote. When the SDK prepares a request, it never uses the session's cookie jar because the transport sends The session jar is only read when This is a correctness concern for shared clients and transports. |
|
Okay, this totally changes my understanding of the issue! Given my own misunderstanding, I think it's likely that someone else reading the changelog could also be confused. I did not grasp that this behavior is specific to redirected requests. Yes, the change is that we no longer store the cookie, but the effect is not that "we disabled cookies" or any such generic change in behavior. Would it be accurate to phrase things like so?
|
|
Rephrasing the changelog fragment seems worthwhile. I've drafted this: Fixed
-----
- Fix session cookies being stored and sent on redirected requests. (:pr:`NUMBER`)
Previously, the SDK would not send session cookies when making an HTTP request,
but if the request was subsequently redirected then session cookies could be added.
Now, ``RequestsTransport`` no longer stores cookies set by responses.Would that clarify the situation? |
|
Yep, that phrasing is excellent, and clear to me! I'm about to crack things open and read through the implementation. |
| """ | ||
|
|
||
| # the attributes which `http.cookiejar.CookieJar` reads from its policy | ||
| netscape = True |
There was a problem hiding this comment.
Why is netscape = True set, when the others are false? It stands out, so I'm curious.
"no cookies" suggests to me that all three flags should be false.
I tried flipping this to netscape = False and the testsuite passed in my runs.
Is there some knock-on effect of turning all three off?
There was a problem hiding this comment.
CookiePolicy defines some methods that all subclasses should override. However, the subclass DefaultCookiePolicy sets several instance variables that other places in the standard library access as attributes.
These class variables exist solely to prevent AttributeError from elsewhere within the standard library. Their values don't have a functional purpose, but it'll be clearer if they all say False, rather than happening to match the defaults set by DefaultCookiePolicy.
I'll update this.
790e319 to
977996a
Compare
sirosen
left a comment
There was a problem hiding this comment.
This is a good change and deserves more than a rote approval!
Here's a nice bit of architecture trivia, as payment for your good work:
https://en.wikipedia.org/wiki/Mullion
Fixed
RequestsTransportno longer stores cookies set by responses. (:pr:NUMBER)Previously, a cookie set by one response could be sent on a later, unrelated request
that was redirected, if the client or transport was shared.